package com.me.study.arithmeticAndDataStructure.arithmetic;

/**
 * 微信红包算法
 *
 * @author ME
 * @date   2019/9/10
 */
public class RedBag {

    public static void main(String[] args) {
        double min = 0.01;
        double total = 100.0;
        int count = 10;

        double last = total - min * count;

        for (int i = 0; i < count - 1; i++) {
            double avg = last / (count - i);
            double get = Math.random() * avg * 2 + min;
            System.out.println("第" + (i + 1) + "个:" + get);
            last = last - get;
        }
        //last one
        System.out.println("第" + count + "个" + (last + min));
    }
}
